<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('')" />
    <th:block th:include="include :: datetimepicker-css" />
    <script type='text/javascript' src='/libs/jquery-3.6.0.min.js'></script>
    <script type='text/javascript' src='/libs/formUtil.js'></script>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form lay-filter='formId' id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>衡器号：</label>
                                <select name="waCode" th:with="type=${@commdict.getDictList('womp_weighing_apparatus,code,name')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>日期范围：</label>
	                            <input type="text" class="input-sm" id="laydate-startTime" name="beginDate" placeholder="yyyy-MM-dd"/>
	                            <span>到</span>
	                            <input type="text" class="input-sm" id="laydate-endTime" name="endDate" placeholder="yyyy-MM-dd"/>
                            </li>
                            <li>
                                <label>告警要素：</label>
                                <select name="ecode" th:with="type=${@commdict.getDictList('womp_element,code,name')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="state" th:with="type=${@dict.getType('alarm_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="allIgnore()" shiro:hasPermission="womp:alarm:allIgnore">
                    <i class="fa"></i> 全部忽略
                </a>
                <a class="btn btn-primary" onclick="conditionIgnore()" shiro:hasPermission="womp:alarm:conditionIgnore">
                    <i class="fa"></i> 条件忽略
                </a>
                <a class="btn btn-danger multiple disabled" onclick="checkIgnore()" shiro:hasPermission="womp:alarm:checkIgnore">
                    <i class="fa"></i> 选中忽略
                </a>
                <a class="btn btn-danger" onclick="conditionDelete()" shiro:hasPermission="womp:alarm:checkIgnore">
                    <i class="fa"></i> 条件删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
    	var alarmHandleFlag = [[${@permission.hasPermi('womp:alarm:handle')}]];
        var editFlag = [[${@permission.hasPermi('womp:alarm:edit')}]];
        var removeFlag = [[${@permission.hasPermi('womp:alarm:remove')}]];
        var waCodeDatas = [[${@commdict.getDictList('womp_weighing_apparatus,code,name')}]];
        var ecodeDatas = [[${@commdict.getDictList('womp_element,code,name')}]];
        var stateDatas = [[${@dict.getType('alarm_type')}]];
        var prefix = ctx + "realtime";

        var options;
        $(function() {
            options = {
                url: prefix + "/alarmList",
                modalName: "告警列表",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'waCode',
                    title: '衡器号',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(waCodeDatas, value);
                    }
                },
                {
                    field: 'id',
                    title: '告警编号'
                },
                {
                    field: 'code',
                    title: '告警要素',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(ecodeDatas, value);
                    }
                },
                {
                    field: 'orderNum',
                    title: '传感器序号'
                },
                {
                    field: 'value',
                    title: '告警值'
                },
                {
                    field: 'message',
                    title: '告警内容'
                },
                {
                    field: 'time',
                    title: '告警时间'
                },
                {
                    field: 'state',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(stateDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.state==0){
                        	actions.push('<a class="btn btn-success btn-xs ' + alarmHandleFlag + '" href="javascript:void(0)" onclick="openAlarmHandle(\'' + row.id + '\')"><i class="fa fa-edit"></i>下发工单</a> ');
                        }
                        //actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        //actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            layui.use('laydate', function(){
         		var laydate = layui.laydate;
	            var startDate = laydate.render({
			        elem: '#laydate-startTime',
			        max: $('#laydate-endTime').val(),
			        theme: 'molv',
			        trigger: 'click',
			        done: function(value, date) {
			            // 结束时间大于开始时间
			            if (value !== '') {
			                endDate.config.min.year = date.year;
			                endDate.config.min.month = date.month - 1;
			                endDate.config.min.date = date.date;
			            } else {
			                endDate.config.min.year = '';
			                endDate.config.min.month = '';
			                endDate.config.min.date = '';
			            }
			        }
			      });
	       		
			      var endDate = laydate.render({
			        elem: '#laydate-endTime',
			        min: $('#laydate-startTime').val(),
			        theme: 'molv',
			        trigger: 'click',
			        done: function(value, date) {
			            // 开始时间小于结束时间
			            if (value !== '') {
			                startDate.config.max.year = date.year;
			                startDate.config.max.month = date.month - 1;
			                startDate.config.max.date = date.date;
			            } else {
			                startDate.config.max.year = '';
			                startDate.config.max.month = '';
			                startDate.config.max.date = '';
			            }
			        }
			    });
            });
        });
		function openAlarmHandle(alarmId){
			$.modal.open('下发工单', '/realtime/toNewWorkOrder?alarmId=' + alarmId, '1200', '600');
		}
		function allIgnore(){
			$.modal.confirm("确认要忽略全部告警吗?", function() {
				var data=$('#formId').serialize()
				$.operate.post("/realtime/alarm/allIgnore?"+data, {},function(data){
					$.table.init(options);
		        });
	    	});
		}
		function conditionIgnore(){
			$.modal.confirm("确认要忽略当前检索数据吗?", function() {
				var data=$('#formId').serialize()
				$.operate.post("/realtime/alarm/conditionIgnore?"+data, {},function(data){
					$.table.init(options);
		        });
	    	});
		}
		function checkIgnore(){
			$.modal.confirm("确认要忽略当前选中数据吗?", function() {
				var rows =$.table.selectColumns('id');
				$.operate.post("/realtime/alarm/checkIgnore?ids="+rows.join(','), {},function(data){
					$.table.init(options);
		        });
	    	});
		}
		function conditionDelete(){
			$.modal.confirm("确认要删除当前检索的所有未处理告警吗?", function() {
				var data=$('#formId').serialize()
				$.operate.post("/realtime/alarm/conditionDelete?"+data, {},function(data){
					$.table.init(options);
		        });
	    	});
		}
    </script>
</body>
</html>